//初始化表单
function initSearchForm(){
	$("#pageNo").val(0);
	return true;
}
//初始化下拉框的值 默认存储到data属性
function initSelectValue(flag) {
	$("select").each(function() {
		var data = $(this).attr("data");
		if (data != "") {
			data = data.split(",");
			$(this).val(data);
		}
	});
	if(flag){
		$('select').selected();
	}
}
//过滤特殊字符
function filterCharacter(s) {
    var pattern = new RegExp("[` ~!@#$^&*()=|{}':;'\\[\\].<>/?~！@#￥……&*（）&mdash;—|{}【】‘；：”“'。，、？]")
        var rs = "";
    for (var i = 0; i < s.length; i++) {
        rs = rs + s.substr(i, 1).replace(pattern, '');
    }
    return rs;
}
//去掉所有的html标记
function delHtmlTag(html){
	return html.replace(/<[^>]+>/g,"");
}
//询问对话框
function iuConfirm(msg, href) {
	layer.confirm(msg, {
		shade:0.01,
		offset: '30px',
		btn : [ '确定', '取消' ]
	}, function() {
		window.location.href=href;
	});
	return false;
}
//弹出提示
function iuAlert(msg){
	top.layer.alert(msg,{offset: '55px',shade:0.001});
}
//弹出消息提示
function iuMsg(msg){
	top.layer.msg(msg,{offset: '55px'});
}
//打开全屏框 是否显示顶部和底部
function openModel(title,url,width,height){
	if(width==undefined || width==null){
		width = '800px';
	}
	if(height==undefined || height==null){
		height = '500px';
	}
	layer.open({
		type: 2,
		title: title,
		offset: '15px',
		shade:0.001,
		area: [width, height],
		content: url
	});
}
//关闭弹出框
function closeModel(isRefresh){
	var index = parent.layer.getFrameIndex(window.name);
	if(isRefresh){
		//刷新页面
		parent.location.reload(true);
	}
	parent.layer.close(index);
}
//重新加载页面
function reloadPage(){
	var index = parent.layer.getFrameIndex(window.name);
	parent.layer.full(index)
}
//ajax get数据
function get(url,call){
	$.ajax({
		type: "GET",
		url: url,
		timeout:30000,
		dataType: "json",
		success:function(data){
			call && call(data);
		},
		error:function(XMLHttpRequest, textStatus, errorThrown){
			console.log(XMLHttpRequest);
			console.log(textStatus);
			console.log(errorThrown);
		}
	});
}
//ajax post数据
function post(url,param,call){
	$.ajax({
		type: "POST",
		url: url,
		data: param,
		timeout:30000,
		dataType: "json",
		success:function(data){
			call && call(data);
		},
		error:function(XMLHttpRequest, textStatus, errorThrown){
			console.log(XMLHttpRequest);
			console.log(textStatus);
			console.log(errorThrown);
		}
	});
}
//时间格式转换 var time = date.format('yyyy-MM-dd h:m:s');
Date.prototype.format = function(format) {
	var date = {
		"M+": this.getMonth() + 1,
		"d+": this.getDate(),
		"h+": this.getHours(),
		"m+": this.getMinutes(),
		"s+": this.getSeconds(),
		"q+": Math.floor((this.getMonth() + 3) / 3),
		"S+": this.getMilliseconds()
	};
	if (/(y+)/i.test(format)) {
		format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
	}
	for (var k in date) {
		if (new RegExp("(" + k + ")").test(format)) {
			format = format.replace(RegExp.$1, RegExp.$1.length == 1
				? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
		}
	}
	return format;
}
//设置cookie
function setCookie(name,value){
	document.cookie = name + "="+ escape (value) + ";expires=" + -1;
}
//读取cookie
function getCookie(name){
	var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
	if(arr=document.cookie.match(reg))
		return unescape(arr[2]);
	else
		return null;
}